<?php

include_once 'model/User.php';
include_once 'BaseView.php';
include_once 'PostDisplayer.php';

class MainView extends BaseView {
	
	private $user;
	
	/*public function setData($data) {
		$this->user=new User();
		$this->user=$data;
	}*/
	
	public function render() {	
		echo '<div id="page-content" class="'.($this->data->pageOwner ? 'user' : 'default').'">';
		echo '<div id="posts-wrapper" class="'.($this->data->pageOwner ? 'user' : 'default').'">';
		if($this->data->pageOwner && $this->data->pageOwner == $this->data->loggedUserName)
			echo '<div id="add-new-post"><a href="'.URI::getUrl('create', $this->data->pageOwner).'">Dodaj nowy post</a></div>';
		if(!isset($this->data->posts))
			echo 'Ten użytkownik nie dodał jeszcze żadnych postów. Zajrzyj tu później.';
		else {
			/*foreach($this->data->posts as $post) {
				PostDisplayer::displayPost($post, $this->data->loggedUserName, $this->data->pageOwner ? true : false);
			}*/
			for($i = $this->data->maxId; $i > 0; --$i) {
				if(isset($this->data->posts[$i])) {
					//echo $i;
					//$post = $this->data->posts[$i];
					//echo $this->data->posts[$i]->getUser()->getId();
					PostDisplayer::displayPost($this->data->posts[$i], $this->data->loggedUserName, $this->data->pageOwner ? true : false);
				}
			}
		}
		echo '</div>';
		if($this->data->nextPage) {
			echo '<div class="navigation-button"><a href="'.URI::getUrl(null, $this->data->pageOwner, null, $data->nextPageFirstPost ).'">starsze posty</a></div>';
		}
		echo '</div>';
	}
	
}

?>